<!--签约面签-->
<template>
  <div>
    <el-form :model="checkForm" label-width="100px" class="demo-ruleForm" ref="checkForm" :disabled="formDisabled">
      <el-form-item label="办理结果" prop="approveStatus" :rules="{required: true, message: '请选择办理结果'}">
        <el-radio-group v-model="checkForm.approveStatus"  @change="handleChange" >
          <el-radio :label="3" class="red">退件</el-radio>
          <el-radio :label="9" class="red">通过</el-radio>
        </el-radio-group>
      </el-form-item>

      <div v-if="approveStatusPass">
        <el-form-item label="面签时间" prop="signTime" :rules="{required: true, message: '请选择面签时间'}">
          <el-date-picker v-model="checkForm.signTime" align="right" type="datetime" placeholder="请选择面签时间" value-format="yyyy-MM-dd HH:mm:ss"/>
        </el-form-item>
      </div>
      <el-form-item label="说明" prop="opinion">
        <el-input type="textarea" :rows="7" v-model="checkForm.opinion" style="width: 300px" placeholder="请输入说明，最多可输入100字" maxlength="100" show-word-limit/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('checkForm')" v-loading="loading" v-if="isTaskProcessing">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import { getReviewByTaskId, signReview,getAppReviewByProjectId } from '@/api/creditLoan'
export default {
  props: {
    projectId: undefined,
    isTaskProcessing: undefined,
    taskId: undefined,
    currentNodeProjectStatus: undefined   // 当前节点的项目状态
  },
  data() {
    return {
      checkForm: {
        approveStatus: undefined,
        opinion: undefined,
        signTime: undefined,
        projectId: undefined,
        taskId: undefined
      },
      loading: false,
      approveStatusPass: false,
      formDisabled: false
    };
  },

  created: function () {
    this.taskId = this.$route.query.taskId;
    if (this.isTaskProcessing === undefined){
      this.isTaskProcessing = false;
    }
    if (this.isTaskProcessing == false){
      this.getReviewByTaskId();
      this.formDisabled = true;
    }
  },

  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.checkForm.projectId = this.projectId,
          this.checkForm.taskId = this.taskId,
          this.$confirm('你确定要提交吗?', '提示', {
            confirmButtonText: '确定',cancelButtonText: '取消',type: 'warning',
          }).then(() => {
            // 开始提交信息
            this.loading = true;
            signReview(this.checkForm).then((data) => {
              this.loading = false;
              this.$notify.success({title: '成功',message: '操作成功'})
              this.$store.dispatch("tagsView/delView", this.$route);
              this.$router.go(-1);
            }).catch(() => {
              this.loading = false
            })
          })
        } else {
          return false
        }
      })
    },

    // 查询当审批信息
    getReviewByTaskId() {
      this.loading = true;
      getReviewByTaskId(this.taskId).then((data) => {
        this.checkForm=data.data
        if (data.data.approveStatus === 9){
          this.approveStatusPass = true;
        }
      });
      this.loading = false;
    },

    // 获取当前项目的APP审核最新信息
    getAppReviewByProjectId() {
      this.loading = true;
      getAppReviewByProjectId(this.projectId).then((data) => {
        this.checkForm.signTime = data.data.signTime
        console.log('响应数据:%o', data.data);
      });
      this.loading = false;
    },

    handleChange(node) {
      this.$refs['checkForm'].resetFields() // 重置表单
      this.checkForm.approveStatus = node
      this.approveStatusPass = false;
      if (node == 9){
        this.approveStatusPass = true;
        this.getAppReviewByProjectId();
      }
    }
  }
}
</script>
